package com.hongsen.cn.Utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.hongsen.cn.application.DayAndMonthApplication;

public class SPUtil {

    private static final String SHARE_PREFS_NAME = "data";

    public static void putBoolean(String key, boolean value) {
        SharedPreferences pref = DayAndMonthApplication.getInstance().getSharedPreferences(SHARE_PREFS_NAME,
                Context.MODE_PRIVATE);

        pref.edit().putBoolean(key, value).commit();
    }

    public static boolean getBoolean(String key,
                                     boolean defaultValue) {
        SharedPreferences pref = DayAndMonthApplication.getInstance().getSharedPreferences(SHARE_PREFS_NAME,
                Context.MODE_PRIVATE);

        return pref.getBoolean(key, defaultValue);
    }

    /**
     * 保存时 值
     * 非加密
     */
    public static void putString(String key, String value) {
        SharedPreferences pref = DayAndMonthApplication.getInstance().getSharedPreferences(SHARE_PREFS_NAME,
                Context.MODE_PRIVATE);
        pref.edit().putString(key, TextUtils.isEmpty(value) ? "" : value).commit();
    }

    /**
     * 获取时 值
     * 非加密
     */
    public static String getString(String key, String defaultValue) {
        SharedPreferences pref = DayAndMonthApplication.getInstance().getSharedPreferences(SHARE_PREFS_NAME,
                Context.MODE_PRIVATE);
        return pref.getString(key, defaultValue);
    }

    public static void putInt(String key, int value) {
        SharedPreferences pref = DayAndMonthApplication.getInstance().getSharedPreferences(SHARE_PREFS_NAME,
                Context.MODE_PRIVATE);

        pref.edit().putInt(key, value).commit();
    }

    public static int getInt(String key, int defaultValue) {
        SharedPreferences pref = DayAndMonthApplication.getInstance().getSharedPreferences(SHARE_PREFS_NAME,
                Context.MODE_PRIVATE);

        return pref.getInt(key, defaultValue);
    }
}
